package com.bing.util;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * Created by kaibb on 2014/11/29.
 */
@Service
public class CacheEntry {
    public static Random random = new Random(10000);
    public static int count = 0;

    @Cacheable(value = "testCache", key = "#s")
    public String getCode(String s) {
        System.out.println("testGetCode.......");
        return s + random.nextInt();
    }

    //除非result!=
    @Cacheable(value = "testCache", key = "#s", unless = "#result == null")
    public String getCode2(String s) {
        System.out.println("getCode2: " + s);
        count++;
        if (s.startsWith("abc")) {
            return "abc";
        }
        return s + random.nextInt();
    }
}
